package client;

import java.io.IOException;
import java.rmi.*;
import server.*;

public class Client {

    public static Object bytesToObject(byte bytes[]) throws IOException, ClassNotFoundException {
        Object res;
        java.io.ObjectInputStream in;
        java.io.ByteArrayInputStream bs;
        bs = new java.io.ByteArrayInputStream(bytes, 0, bytes.length-30);
        in = new java.io.ObjectInputStream(bs);
        res = in.readObject();
        in.close();
        bs.close();
        return res;
    }

    public static void main(String[] args) throws RemoteException {

        //Setting player name


        //connect to the server: Manager
        System.setSecurityManager(new RMISecurityManager());
        ManagerInf manager = null;
        try {
            if (args[0]!= null)
                manager = (ManagerInf) Naming.lookup("//"+args[0]+"/Server");
            else
                manager = (ManagerInf) Naming.lookup("//localhost/Server");
            ClientGUI c = new ClientGUI(manager);
            c.setVisible(true);
        //manager.UpdateAMap();
        //Display your map
        //Display maps for all players on same game 0
        //If close the maps
        //leaveAMap()
        //Thats All

        //Another Thread
        //wait for A change of any map or any player leave the game
        //receive that map and override current, or
        //override the current players information.

        //Another Thread
        //wait for leave

        } catch (RemoteException exc) {
            System.out.println("Error in lookup: " + exc.toString());
        } catch (java.net.MalformedURLException exc) {
            System.out.println("Malformed URL: " + exc.toString());
        } catch (java.rmi.NotBoundException exc) {
            System.out.println("NotBound: " + exc.toString());
        }
    }
}
